package com.sms.servlet;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.sms.model.PageBean;
import com.sms.pojo.SmsClass;
import com.sms.service.ClassService;
import com.sms.utils.StringUtils;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.ContextLoader;

@Controller
@RequestMapping("class")
public class ClassController {

    @Autowired
    private ClassService classService;

    @RequestMapping("goAddClass")
    public String goAddUser(HttpSession session, Model model) {
        session.removeAttribute("insertmessage");
        session.removeAttribute("editmassage");
        return "add-class";
    }


    @RequestMapping(value = "/addClass")
    public String addClass(Model model, SmsClass smsClass) {
        try {
            System.out.println("addUser" + smsClass.toString());
            classService.addClass(smsClass);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "redirect:/class/queryClass";
    }

    @RequestMapping("queryClass")
    public String queryClassList(@RequestParam(value = "page", defaultValue = "1") int page,
                                 @RequestParam(value = "pageSize", defaultValue = "5") int pageSize,
                                 Model model, HttpSession session, SmsClass smsClass) {
        PageInfo<SmsClass> classPageInfo = classService.queryClassPage(page, pageSize, smsClass);
        System.out.println("====所有用户信息===" + classPageInfo.getList());
        model.addAttribute("classPageInfo", classPageInfo);
        return "class-list";
    }
}
